package com.sinosoft.msf.base.supplier.controller;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.RandomUtil;

import com.sinosoft.msf.base.supplier.pojo.RestEntity;
import com.sinosoft.msf.base.supplier.pojo.ValiComInfoPojo;
import com.sinosoft.msf.base.supplier.service.CompanyService;
import com.sinosoft.msf.base.supplier.service.ProjectService;
import com.sinosoft.msf.base.supplier.service.SupSendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sup/send")
public class SupSendController {
    @Autowired
    ProjectService projectService;
    @Autowired
    SupSendService sendService;
    @Autowired
    CompanyService companyService;
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @PostMapping(value = "/login", name = "登录")
    public RestEntity valiComInfo(@RequestBody ValiComInfoPojo comInfoPojo) {
        Validator.validateNotEmpty(comInfoPojo.getName(), "请输入公司名称");
        Validator.validateNotEmpty(comInfoPojo.getPhone(), "请输入手机号");
        Validator.validateNotEmpty(comInfoPojo.getValiCode(), "请输入验证码信息");
        String comId = companyService.valiPhone(comInfoPojo);
        sendService.valiPhoneCode(comInfoPojo.getPhone(), comInfoPojo.getValiCode(),comInfoPojo.getName());
        return RestEntity.data(comId);
    }
    @PostMapping(value = "/smsForCom", name = "根据供应商信息发送短信")
    public RestEntity sendSmsForComInfo(@RequestBody ValiComInfoPojo comInfoPojo ) {
        Validator.validateNotEmpty(comInfoPojo.getName(), "请输入公司名称");
        Validator.validateNotEmpty(comInfoPojo.getPhone(), "请输入联系人手机号");
        companyService.valiPhone(comInfoPojo);
        String code = RandomUtil.randomNumbers(6);
        sendService.sendSms(comInfoPojo.getPhone(), code,comInfoPojo.getName());
        return RestEntity.data("发送成功");
    }
    @PostMapping(value = "/sms", name = "发送短信")
    public RestEntity addCompany(@RequestBody ValiComInfoPojo comInfoPojo) {
        Validator.validateNotEmpty(comInfoPojo.getId(), "缺少项目信息");
        Validator.validateNotEmpty(comInfoPojo.getPhone(), "缺少手机号信息");
        projectService.valiPhone(comInfoPojo);
        String code = RandomUtil.randomNumbers(6);
        sendService.sendSms(comInfoPojo.getPhone(), code,"");
        return RestEntity.data("发送成功");
    }


}
